/* ==================================================================   
 * Created [2009-4-27 下午11:32:55] by Jon.King 
 * ==================================================================  
 * TSS 
 * ================================================================== 
 * mailTo:jinpujun@hotmail.com
 * Copyright (c) Jon.King, 2009-2012 
 * ================================================================== 
 */

package com.jinhe.tss.component.dynproperty;

import java.util.List;

import com.jinhe.tss.component.dynproperty.entity.DynableEntity;
import com.jinhe.tss.component.dynproperty.support.hibernate.DynAbstractHibernateDao;
import com.jinhe.tss.core.persistence.IEntity;
 
public class PropertyDaoImpl extends DynAbstractHibernateDao implements PropertyDao {
    
    public PropertyDaoImpl() {
        super(IEntity.class);
    }
 
    public Integer getNextOrderByPId(Long parentId) {
        List<?> list = getEntities("select nvl(max(o.seqNo), 0) + 1 from DynableEntity o where o.parentId = ?", parentId);
        return (!list.isEmpty() && list.get(0) != null) ? (Integer) list.get(0) : new Integer(1);
    }
    
    public Integer getNextSeqNo(String entityCode) {
        List<?> list = getEntities("select nvl(max(o.seqNo), 0) + 1 from PropertyDef o where o.entityCode = ?", entityCode);
        return (!list.isEmpty() && list.get(0) != null) ? (Integer) list.get(0) : new Integer(1);
    }
    
    public Integer getTabNextSeqNo(Long xformTemplateId){
        List<?> list = getEntities("select nvl(max(o.seqNo), 0) + 1 from XFormTemplateTab o where o.xformTemplateId = ?", xformTemplateId );
        return (!list.isEmpty() && list.get(0) != null) ? (Integer) list.get(0) : new Integer(1);
    }

    public DynableEntity moveGroupOrEntity(DynableEntity obj) {
        return (DynableEntity) super.create(obj);
    }
}
